import Progress from "../schema/progress";

export const getUserHitNRuns = async (_id) => {
  const progressRecords =
    (await Progress.find({ userId: _id, left: 0 }).lean()) ?? [];

  return progressRecords.filter((p) => {
    // 使用可选链和空值合并操作符进行安全访问
    const uploadedTotal = p.uploaded?.total ?? 0;
    const downloadedTotal = p.downloaded?.total ?? 0;
    return uploadedTotal < downloadedTotal;
  }).length;
};
